<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
    class Func_Permit_Model extends CI_Model{
        function __construct() {
            parent::__construct();
        }
        function get_list_func_by_permit($permission_id){
            if($permission_id!=0){
                $this->db->where('permission_id',$permission_id);
            }
            return $this->db->get('permission_detail')->result();
        }
        function get_permission_by_id(){
          $function_id = $this->uri->segment(3);
          $this->db->where('permission_id',$function_id);
          return $this->db->get('permission')->row();
        } 
        
        function get_all_permission(){
            return $this->db->get('permission')->result();
        } 
        function get_permit_by_id($function_id){
            $this->db->where('permission_id',$function_id);
            return $this->db->get('permission')->row();
        }
        function get_func_by_id($id){
            return $this->db->get_where('permission_detail',array('function_id'=>$id))->row();
        }
        
        function save(){
            $function_id = (int)$this->uri->segment(4);
            $permission_id = (int)$this->input->post('permission_id');
            $check = $this->get_permit_by_id($permission_id);
            $permission_name = $check->permission_name;
            $data = array(
                'permission_id' => $permission_id,
                'permission_name' => $permission_name,
                'function_name' => $this->input->post('function_name'),
                'function_notice' => $this->input->post('function_notice')
            );
            if($function_id!=0){
                $this->db->where('function_id',$function_id);
                if($this->db->update('permission_detail',$data)){
                    return true;
                }else{
                    return false;
                }
            }else{
                if($this->db->insert('permission_detail',$data)){
                    return true;
                }else{
                    return false;
                }
            }
            
        }
        function dels($id)
        {
            $this->db->where('function_id',$id);
            $check = $this->db->get('permission_detail')->row();
            if($check){
                 $this->db->where('function_id',$id);
                 if($this->db->delete('permission_detail')){
                     $this->db->where('function_id',$id);
                     $this->db->delete('permission_admin');
                       return true;
                 }else{
                       return false;
                 }
            }else{
                 return false;
            }
        }
    }  
?>
